<template>
  <zm-panel title="编辑配置提成" :visible.sync="value" @change="close">
    <el-form label-width="80px" :model="form" :rules="formRule" ref="form">
      <cinema-radio v-model="form" label-width="80px"></cinema-radio>
      <el-form-item label="提成比例" prop="proportionOne">
        <span>（实际应收-最低销售单价*剩余数量）*回款金额 / 实际应收 *</span>
        <zm-input class="w150" v-model="form.proportionOne" type="number" clearable>
          <template slot="append">%</template>
        </zm-input>
        <span>* 逾期天数%</span>
      </el-form-item>
    </el-form>
    <div slot="footer" class="tr">
      <el-button @click="close">取 消</el-button>
      <el-button type="primary" @click="submit">确 定</el-button>
    </div>
  </zm-panel>
</template>

<script>
import panelMixin from '@/mixins/panelMixin'
import overdueRuleApi from '@/api/src/overdueRule'
import commissionRuleApi from '@/api/src/commissionRule'
import CinemaRadio from '@/views/product/components/CinemaRadio'
import { STRING_NUMBER } from '@/utils/validateRule'

export default {
  name: 'GoodsExpressionEdit',
  components: { CinemaRadio },
  mixins: [panelMixin],
  props: {
    obj: {
      type: Object,
      default: () => {
        return {}
      }
    }
  },
  data () {
    return {
      form: {
        orderType: '4', // 类型: 4包场 6 实物
        proportionOne: '',
        proportionTwo: '',
        proportionThree: '',
        relationType: '-1', // 影院数据：-1 全部影院 1 影院分组 2 指定影院
        relationId: ''
      },
      formRule: {
        proportionOne: [
          {
            required: true,
            message: '请输入提成比例!'
          }, { validator: STRING_NUMBER, trigger: 'blur' }
        ]
      }
    }
  },
  mounted () {

  },
  created () {
    if (this.obj.id) {
      this.getDetail()
    }
  },
  methods: {
    async getDetail () {
      const res = await commissionRuleApi.detail({orderType: '4', id: this.obj.id})
      this.form = res
    },
    async submit () {
      let _valid = false
      await this.$refs.form.validate(valid => {
        _valid = valid
      })
      if (!_valid) {
        return
      }
      const res = await commissionRuleApi.createOrUpdate(this.form)

      this.$emit('after-save')
      this.$msg.success()
      this.close()
    }
  }
}
</script>
